
function arrange(arr) {
    let results = [], result = [];
    doExchange(arr, 0);
    function doExchange(arr, depth) {
        for (let i = 0; i < arr[depth].length; i++) {
            result[depth] = arr[depth][i]
            if (depth != arr.length - 1) {
                doExchange(arr, depth + 1)
            } else {
                results.push(result.join('_'))
            }
        }
    }
}
arrange(
    [
        ['a', 'b', 'c'],
        ['1', '2', '3'],
        ['x', 'y'],
        ['c', 'd', 'g']
    ]
)